package com.slj.springcloud.handler;

import com.slj.springcloud.model.response.Result;
import com.slj.springcloud.model.response.ResultCode;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result<Void> globalException(HttpServletResponse response, Exception ex) {
        log.error(ex.getMessage());
        return Result.error(ResultCode.INTERNAL_SERVER_ERROR);
    }
}
